package com.ant.storage.controller;

import com.ant.storage.common.ResultVo;
import com.ant.storage.pojo.Role;
import com.ant.storage.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
@Api(tags = "员工接口")
public class RoleController {

    @Autowired
    IRoleService roleService;

    @ApiOperation(value = "获取员工列表")
    @GetMapping("/queryRoleList")
    public ResultVo queryRoleList() {
        List<Role> roleList = roleService.list();
        return ResultVo.success("操作成功",roleList);
    }

    @ApiOperation(value = "添加角色")
    @PostMapping("/saveRole")
    public ResultVo saveRole(@RequestBody Role role) {
        if(role.getRoleName() == null || role.getRoleName().trim().equals("")){
            return ResultVo.failure(201,"名称不能为空");
        }
        if(role.getRoleValue() == null || role.getRoleValue().trim().equals("")){
            return ResultVo.failure(201,"值不能为空");
        }
        if (role.getId() == null) {
            roleService.save(role);
        } else {
            roleService.updateById(role);
        }
        return ResultVo.success("操作成功");
    }

}
